package com.admin.business.workManagement.venusOaWorkComplete;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 完成工作记录提醒表
 * @create: 2023-11-14 15:21:40
 **/
@Service("venusOaWorkCompleteService")
@Slf4j
public class VenusOaWorkCompleteService{

    @Resource
    VenusOaWorkCompleteDao venusOaWorkCompleteDao;

    /**
     * 添加完成工作记录提醒表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - work_id:工作id
     *                   - user_id:查看人id
     *                   - begtime:查看时间
     *                   - see_state:上级是否看过(0 没看过 1 已读)
     *                   - type:工作类型(1 工作安排 2 循环计划 3 工作记录 4 工作汇报)
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:40
     */
    @OpenApi
    public Return addVenusOaWorkComplete(CDO cdoRequest) {
        venusOaWorkCompleteDao.addVenusOaWorkComplete(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新完成工作记录提醒表数据
     *
     * @param cdoRequest - id:主键
     *                   - work_id:工作id
     *                   - user_id:查看人id
     *                   - begtime:查看时间
     *                   - see_state:上级是否看过(0 没看过 1 已读)
     *                   - type:工作类型(1 工作安排 2 循环计划 3 工作记录 4 工作汇报)
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:40
     */
    @OpenApi
    public Return updateVenusOaWorkCompleteById(CDO cdoRequest) {
        venusOaWorkCompleteDao.updateVenusOaWorkCompleteById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除完成工作记录提醒表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:40
     */
    @OpenApi
    public Return deleteVenusOaWorkCompleteById(CDO cdoRequest){
        int count = venusOaWorkCompleteDao.deleteVenusOaWorkCompleteById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除完成工作记录提醒表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:40
     */
    @OpenApi
    public Return deleteVenusOaWorkComplete(CDO cdoRequest) {
        int count = venusOaWorkCompleteDao.deleteVenusOaWorkComplete(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取完成工作记录提醒表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:40
     */
    @OpenApi
    public Return getVenusOaWorkCompleteById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaWorkCompleteDao.getVenusOaWorkCompleteById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取完成工作记录提醒表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:40
     */
    @OpenApi
    public Return getVenusOaWorkCompleteListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaWorkCompleteDao.getVenusOaWorkCompleteListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaWorkCompleteDao.getVenusOaWorkCompleteCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取完成工作记录提醒表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:40
     */
    @OpenApi
    public Return getVenusOaWorkCompleteListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaWorkCompleteDao.getVenusOaWorkCompleteListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaWorkCompleteDao.getVenusOaWorkCompleteCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
